package Producer

import (
	"deepgox-go-admin/Settings"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/producer"
	"go.uber.org/zap"
)

var (
	NProducer *rocketmq.Producer
)

func Init(cfg *Settings.RocketmqConfig) (NProducer rocketmq.Producer, err error) {
	// 消息消费失败重试两次
	NProducer, err = rocketmq.NewProducer(
		producer.WithNameServer(cfg.NameServer),
		producer.WithRetry(2),
	)
	if err = NProducer.Start(); err != nil {
		zap.L().Error("Init RProducer failed", zap.Error(err))
		return
	}
	return NProducer, err
}
